<?php

/**
 * contact : 刘经理 19326416371
 * company : 版权所属 四川北星惯牌科技有限公司
 **/

namespace app\common\library\Map;
use app\common\library\Map\Factory\Tencent;
use app\common\library\Map\Factory\Amap;
use app\common\library\Map\Factory\Baidu;

/**
 * 地图服务
 */
class Map
{
    protected $config;
    protected $map;
    private $response;
    public function __construct($config)
    {
        $this->config = $config;
        $MapType = ucfirst($this->config['maptype']);
        $mapTypeConfig = config("app.{$MapType}");
        $merge['secret'] = $mapTypeConfig['secret'];
        $config = array_merge($this->config, $merge);
        switch ($MapType){
            case 'Baidu':
                $this->map = new Baidu($config);
                break;
            case 'Tencent':
                $this->map = new Tencent($config);
                break;
            case 'Amap':
                $this->map = new Amap($config);
                break;
            default:
                break;

        }
    }

    public function getInfoByIp(string $ip)
    {
        $this->response = $this->map->getInfoByIp($ip);
    }

    public function getInfoByAddress(string $address)
    {
        $this->response = $this->map->getInfoByAddress($address);
    }

    public function getInfoByLocation(string $location)
    {
        $this->response = $this->map->getInfoByLocation($location);
    }

    public function getResponse()
    {
        return $this->response;
    }
}
